// pages/partner/index.js
const util = require('../../utils/util.js')
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabArr: {
      curHdIndex: 0,
      curBdIndex: 0
    },
    currentTab: 0,
    page:1,

    usercount1: 0,
    usercount2: 0,
    usercount3: 0,
    userInforArray1: [


    ],
    userInforArray2: [


    ],
    userInforArray3: [


    ],
    loadmoretext:"点击加载更多"

  },
  //事件处理函数
  tabFun: function (e) {
    //获取触发事件组件的dataset属性  
    var _datasetId = e.target.dataset.id;
    var _obj = {};
    _obj.curHdIndex = _datasetId;
    _obj.curBdIndex = _datasetId;
    this.setData({
      tabArr: _obj
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getPartner();

  },
  nextpage:function(){
      console.log("加载更多");
    var nextpage=this.data.page+1;
    console.log("加载更多"+nextpage);
    this.setData({'page':nextpage});
    this.getPartner();
  },
  getPartner: function (e) {
    var $that = this;

    app.util.request({
      url: 'entry/wxapp/Myteam',
      data: {
        "m": 'nets_haojk',
        "page":$that.data.page
      },
      method: 'post',
      success: function (response) {
          
        console.log(response);
        var res = response.data.data;
        if (res.team1.length==0){
            $that.setData({"loadmoretext":"没有更多了"});
        }
        // var team_user = $that.data.userInforArray3;
        var team1 = $that.data.userInforArray1;
         var team2 = $that.data.userInforArray2;
         var team3 = $that.data.userInforArray3;
        for (var i = 0; i < res.team0.length; i++) {
          
            team1.push(res.team0[i]);
          
        }
        for (var i = 0; i < res.team1.length; i++) {

            team2.push(res.team1[i]);

        }
        for (var i = 0; i < res.team2.length; i++) {

            team3.push(res.team2[i]);

        }
        // for (var i = 0; i < res.team2.length; i++) {
        //   // console.log("tt:" + res.team2[i].type);
        //   if (res.team2[i].type == null || res.team2[i].type == 0 || res.team2[i].type == "") {
        //     console.log("user");
        //     team_user.push(res.team2[i]);
        //   } else {
        //     team2.push(res.team2[i]);
        //   }
        // }
        // if(team1.length>1000){
        //     //team1 = team1.slice(0, 1000);
        // }
        // if (team2.length > 1000) {
        //     //team2 = team2.slice(0, 1000);
        // }
        // if (team_user.length > 1000) {
        //     //team_user = team_user.slice(0, 1000);
        // }

        $that.setData({
          userInforArray1: team1,
          userInforArray2: team2,
          userInforArray3: team3,
          usertotal: 0,
          usercount1: 0,
          usercount2: 0,
          usercount3: 0,

        });





        //移除数组中的元素
        function removeArrayItem(e, typenum) {
          console.log(util);
          var result = [];
          for (var i = 0; i < e.length; i++) {
            if (e[i].type == typenum + "") {
              e[i].created_at = form_time(e[i].created_at);
              result.push(e[i]);
            }
          }
          return result;
        }

        //int转时间戳
        function form_time(a) {
          var myDate = new Date(parseInt(a) * 1000);
          var datestr = "";
          datestr = myDate.getFullYear();    //获取完整的年份(4位,1970-????)
          datestr = datestr + "-" + (myDate.getMonth() + 1);       //获取当前月份(0-11,0代表1月)
          datestr = datestr + "-" + myDate.getDate();        //获取当前日(1-31)
          datestr = datestr + " " + (myDate.getHours() < 10 ? "0" : "") + myDate.getHours();        //获取当前日(1-31)
          datestr = datestr + ":" + (myDate.getMinutes() < 10 ? "0" : "") + myDate.getMinutes();        //获取当前日(1-31)
          return datestr;
        }
      }
    });
  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})